package com.hrg.rds.infra.executor;

import com.hrg.rds.biz.waybill.domain.template.cmd.CmdParam;
import lombok.Data;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

@Data
public class CmdInstanceResult {
	private CmdExecutorStatus status;
	private Duration sleep4Retry;
	// 需要反馈到前端的信息
    private String retryMsg;
    private String exceptionMsg;
	private List<CmdParam> outputParams = new ArrayList<>();

	private CmdInstanceResult(CmdExecutorStatus status, Duration sleep4Retry, String retryMsg, String exceptionMsg) {
		this.status = status;
		this.sleep4Retry = sleep4Retry;
		this.retryMsg = retryMsg;
		this.exceptionMsg = exceptionMsg;
	}

	public static CmdInstanceResult success() {
		return new CmdInstanceResult(CmdExecutorStatus.Success, null, null, null);
	}

	public static CmdInstanceResult init() {
		return new CmdInstanceResult(CmdExecutorStatus.Init, null, null, null);
	}
	public static CmdInstanceResult retry() {
		return new CmdInstanceResult(CmdExecutorStatus.Retry, null, null, null);
	}

	public static CmdInstanceResult retry(String retryMsg) {
		return new CmdInstanceResult(CmdExecutorStatus.Retry, null, retryMsg, null);
	}

	public static CmdInstanceResult retry(Duration sleep4Retry, String retryMsg) {
		return new CmdInstanceResult(CmdExecutorStatus.Retry, null, retryMsg, null);
	}

	public static CmdInstanceResult exception(String exceptionMsg) {
		return new CmdInstanceResult(CmdExecutorStatus.Exception, null, null, exceptionMsg);
	}

	public CmdInstanceResult addCmdParams(CmdParam cmdParam) {
		this.outputParams.add(cmdParam);
		return this;
	}

	public CmdInstanceResult addCmdParams(List<CmdParam> cmdParams) {
		this.outputParams.addAll(cmdParams);
		return this;
	}
}
